podTemplate(yaml: '''
    apiVersion: v1
    kind: Pod
    metadata:
      labels: 
        some-label: some-label-value
    spec:
      containers:
      - name: jnlp
        image: kinshy-docker.pkg.coding.net/south/cross/jenkins-agent:maven-3.6.3
        volumeMounts:
          - mountPath: /usr/bin/docker
            name: docker
          - mountPath: /var/run/docker.sock
            name: sock
          - mountPath: /usr/bin/kubectl
            name: kube
      volumes:
        - hostPath:
            path: /usr/bin/docker
            type: ''
          name: docker
        - hostPath:
            path: /var/run/docker.sock
            type: ''
          name: sock
        - hostPath:
            path: /usr/bin/kubectl
            type: ''
          name: kube
    ''') {

    node(POD_LABEL) {
      workdir="/home/jenkins/workdir"
      imageurl="192.168.11.14:5000"
      try{
        stage ('CI'){
            script {
                      if (!fileExists("${workdir}")) {
                         sh "mkdir -p ${workdir}"
                         dir ("${workdir}") {
                             def repositoryUrl = scm.userRemoteConfigs[0].url
                             sh "git init"
                             sh "git remote add origin ${repositoryUrl}"
                             sh "git checkout -b master"
                             sh "git pull origin master"
                         }
                      } else {
                         dir ("${workdir}") {
                             sh "git pull origin master"
                         }
                      }
              if ("${BUILD_PROCESS}" == "init"){
                        dir ("${workdir}"){
                            sh "DOCKER_BUILDKIT=1 docker -H 192.168.11.14:2375 build -t ruoyi-init -f buildkitDockerfile  ."
                        }
              }
                      dir ("${workdir}/ci"){
                          sh "docker -H 192.168.11.14:2375 build -t ${DOCKER_IMAGE_NAME}:${ENV}.${BUILD_NUMBER} --build-arg ENV=${ENV} --build-arg buildname=${DOCKER_IMAGE_NAME} ."
                      }
                   stage ('docker -H 192.168.11.14:2375 Push') {
                          sh "docker -H 192.168.11.14:2375 tag ${DOCKER_IMAGE_NAME}:${ENV}.${BUILD_NUMBER} ${imageurl}/${DOCKER_IMAGE_NAME}:${ENV}.${BUILD_NUMBER}"
                          sh "docker -H 192.168.11.14:2375 push ${imageurl}/${DOCKER_IMAGE_NAME}:${ENV}.${BUILD_NUMBER}"
                      }

            }
        }
        println("##### This operation completed successfully! #####")
        }catch (Exception e) {
          println("##### ERROR Exception: ${e} #####")
        }
    }
}